package com.takeshequ.nearest;

import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.ImageView;
import android.widget.PopupWindow;

import com.takeshequ.R;
import com.takeshequ.main.BasicFragment;
import com.utils.SharedPreferencesUtils;

public class SiftPopupWindow extends PopupWindow {
	private ImageView all, male, female, ok, cancel;
	private View mMenuView;
	private String gender = "";

	public SiftPopupWindow(final Activity context, final Fragment fragment) {
		super(context);
		LayoutInflater inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		mMenuView = inflater.inflate(R.layout.nearest_sift, null);
		all = (ImageView) mMenuView.findViewById(R.id.nearest_sift_all);
		male = (ImageView) mMenuView.findViewById(R.id.nearest_sift_only_male);
		female = (ImageView) mMenuView
				.findViewById(R.id.nearest_sift_only_female);
		ok = (ImageView) mMenuView.findViewById(R.id.nearest_sift_ok_btn);
		cancel = (ImageView) mMenuView
				.findViewById(R.id.nearest_sift_cancel_btn);

		all.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				gender = "";
				male.clearColorFilter();
				female.clearColorFilter();
				all.setBackgroundColor(context.getResources().getColor(
						R.color.orange));
			}
		});
		male.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				gender = "m";
				all.clearColorFilter();
				female.clearColorFilter();
				male.setBackgroundColor(context.getResources().getColor(
						R.color.orange));
			}
		});
		female.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				gender = "w";
				all.clearColorFilter();
				male.clearColorFilter();
				female.setBackgroundColor(context.getResources().getColor(
						R.color.orange));
			}
		});
		ok.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				SharedPreferencesUtils.getInstance(context)
						.setNearestListGender(gender);
				dismiss();
				((BasicFragment) fragment).show();
			}
		});
		cancel.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				dismiss();
			}
		});
		this.setContentView(mMenuView);
		this.setWidth(LayoutParams.FILL_PARENT);
		this.setHeight(LayoutParams.FILL_PARENT);
		this.setFocusable(true);
		this.setAnimationStyle(R.style.AnimBottom);
		ColorDrawable dw = new ColorDrawable(0xb0000000);
		this.setBackgroundDrawable(dw);

	}

}
